
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:reabampos/src/reabam/operation/rb_config.dart';
import 'package:reabampos/src/reabam/ui_self_service/mine/pagestate_ss_setting.dart';
import 'package:reabampos/src/reabam/ui_self_service/pagestate_ss_login.dart';
import 'package:reabampos/src/reabam/utils/rb_color.dart';
import 'package:reabampos/src/reabam/utils/rb_widget.dart';
import 'package:reabampos/src/reabam/utils/rb_widget_ss.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_string.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

/*
手动输入商品编码搜索
 */
class PageStateSelfServiceManualInputGoodItemBarcodeSearch extends XPageState{

  PageStateSelfServiceManualInputGoodItemBarcodeSearch();

  StringBuffer sb=StringBuffer();

  @override
  void onCreate() {
    super.onCreate();
    RBConfigs.isPageScanType=0;
  }

  @override
  Widget getBodyWidget(BuildContext context) {
    return XWidgetUtils.getLayoutCenter(
        XWidgetUtils.getXLayoutRoundedRect(
            height:1311,
            radius_topLeft: 30,
            radius_topRight: 30,
            radius_bottomRight: 30,
            radius_bottomLeft: 30,
            margin: XWidgetUtils.getEdgeInsets(50, 0, 50, 0),
            backgroundColor: Colors.white,
            child:XWidgetUtils.getLayoutColumn(
                children: [
                  XWidgetUtils.getLayoutContainer(
                      width: double.infinity,
                      margin: XWidgetUtils.getEdgeInsets(0, 60, 0, 0),
                      child:XWidgetUtils.getLayoutStack(
                          alignment:AlignmentDirectional.center,
                          children: [
                            XImageUtils.getImageWidgetWithAsset(
                                'ss_gooditem_barcode.png',
                              width: 332,
                              height: 138,
                            ),
                            XWidgetUtils.getLayoutPositioned(
                                top: 0,
                                right: 32,
                                child: XWidgetUtils.getWidgetGestureDetector(
                                    child: XImageUtils.getImageWidgetWithAsset(
                                        'ss_close.png',
                                        width: 70,
                                        height: 70
                                    ),
                                    onTap: (){
                                      finishPage();
                                    }
                                )
                            )
                          ]
                      )
                  ),
                  XWidgetUtils.getXLayoutRoundedRectWithBorder(
                      height: 100,
                      radius_topLeft: 12,
                      radius_topRight: 12,
                      radius_bottomRight: 12,
                      radius_bottomLeft: 12,
                      alignment: Alignment.centerLeft,
                      borderWidth: 3,
                      borderColor: RBColors.reabamColor4,
                      padding: XWidgetUtils.getEdgeInsets(26, 0, 24, 0),
                      margin: XWidgetUtils.getEdgeInsets(80, 92, 80, 0),
                      child: XWidgetUtils.getLayoutRow(
                          children: [
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetText(
                                  XStringUtils.isEmpty(sb.toString())?'请输入商品条形码':sb.toString(),
                                  style: XStyleUtils.getTextStyle(
                                      fontSize: 34,
                                      color: XStringUtils.isEmpty(sb.toString())?XColorUtils.color999999:XColorUtils.color333333
                                  ),
                                )
                            ),
                            XWidgetUtils.getWidgetGestureDetector(
                                child: XImageUtils.getImageWidgetWithAsset(
                                  'ss_del_90.png',
                                  width: 71,
                                  height: 48,
                                ),
                                onTap: (){

                                  if(sb.length!=0){
                                    setState(() {
                                      String temp=sb.toString();
                                      temp=temp.substring(0,sb.length-1);
                                      sb.clear();
                                      sb.write(temp);
                                    });
                                  }

                                }
                            )
                          ]
                      )
                  ),
                  XWidgetUtils.getLayoutContainer(
                      padding: XWidgetUtils.getEdgeInsets(65, 45, 65, 0),
                      child:XWidgetUtils.getLayoutRow(
                          children: [
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '1',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('1');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '2',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('2');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '3',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('3');
                                      });
                                    }
                                )
                            ),
                          ]
                      )
                  ),
                  XWidgetUtils.getLayoutContainer(
                      padding: XWidgetUtils.getEdgeInsets(65, 0, 65, 0),
                      child:XWidgetUtils.getLayoutRow(
                          children: [
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '4',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('4');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '5',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('5');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '6',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('6');
                                      });
                                    }
                                )
                            ),
                          ]
                      )
                  ),
                  XWidgetUtils.getLayoutContainer(
                      padding: XWidgetUtils.getEdgeInsets(65, 0, 65, 0),
                      child:XWidgetUtils.getLayoutRow(
                          children: [
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '7',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('7');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '8',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('8');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '9',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('9');
                                      });
                                    }
                                )
                            ),
                          ]
                      )
                  ),
                  XWidgetUtils.getLayoutContainer(
                      padding: XWidgetUtils.getEdgeInsets(65, 0, 65, 0),
                      child:XWidgetUtils.getLayoutRow(
                          children: [
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '全删',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.clear();
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: const Color(0xFFEEF0F3),
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '0',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: XColorUtils.color333333,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      setState(() {
                                        sb.write('0');
                                      });
                                    }
                                )
                            ),
                            XWidgetUtils.getLayoutExpanded(
                                XWidgetUtils.getWidgetGestureDetector(
                                    child:XWidgetUtils.getXLayoutRoundedRect(
                                        radius_bottomLeft: 17,
                                        radius_bottomRight: 17,
                                        radius_topRight: 17,
                                        radius_topLeft: 17,
                                        height: 126,
                                        margin: XWidgetUtils.getEdgeInsets(15, 15, 15, 15),
                                        backgroundColor: RBColors.reabamColor4,
                                        alignment: Alignment.center,
                                        child: XWidgetUtils.getWidgetText(
                                          '确认',
                                          style: XStyleUtils.getTextStyle(
                                            fontSize: 50,
                                            color: Colors.white,
                                          ),
                                        )
                                    ),
                                    onTap: (){
                                      _submit();
                                    }
                                )
                            ),
                          ]
                      )
                  ),
                ]
            )
        )
    );
  }


  void _submit(){
    if(sb.isNotEmpty){
      finishPage(result: sb.toString());
    }
  }

  @override
  Color getXPageBackgroundColor() {
    return XColorUtils.pageMengcengColor;
  }


  @override
  void onStart() {
  }

  @override
  Future<void> updateData({int pageIndex=1}) async {

  }




}